package com.winbook.layer.controller;

import org.restlet.Application;
import org.restlet.Request;
import org.restlet.Response;
import org.restlet.Restlet;
import org.restlet.data.ChallengeScheme;
import org.restlet.data.LocalReference;
import org.restlet.resource.Directory;
import org.restlet.routing.Route;
import org.restlet.routing.Router;
import org.restlet.routing.Template;
import org.restlet.routing.TemplateRoute;
import org.restlet.security.ChallengeAuthenticator;
import org.restlet.security.MapVerifier;

import com.winbook.layer.Resources.WallPageResource;

public class WinbookApplication extends Application {

	

	@Override
	public Restlet createInboundRoot() {

		
		Router router = new Router(getContext());
//		TemplateRoute imagesDirRoute = router.attach("/images/", new Directory(getContext(), "war:///images"));
//		TemplateRoute stylesDirRoute = router.attach("/styles/", new Directory(getContext(), "war:///styles"));
//		TemplateRoute scriptsDirRoute = router.attach("/scripts/", new Directory(getContext(), "war:///scripts"));
//		
//		imagesDirRoute.getTemplate().setMatchingMode(Template.MODE_STARTS_WITH);
//		stylesDirRoute.getTemplate().setMatchingMode(Template.MODE_STARTS_WITH);
//		scriptsDirRoute.getTemplate().setMatchingMode(Template.MODE_STARTS_WITH);
		
		router.setRoutingMode(Router.MODE_BEST_MATCH);
		
		router.attach("/{project}/WinCondition", WinConditionResource.class);
		router.attach("/{project}/WinCondition/{id}", WinConditionResource.class); 
		router.attach("/{project}/{wallName}", WallPageResource.class);
		
		
		ChallengeAuthenticator guard = new ChallengeAuthenticator(getContext(), ChallengeScheme.HTTP_BASIC, "winbook");
		MapVerifier verifier = new MapVerifier();
		verifier.getLocalSecrets().put("nkukreja@usc.edu", "nkukreja".toCharArray());
		guard.setVerifier(verifier);
		guard.setNext(router);
		
		return guard;
	
	}
	
	

}
